package com.ruoyi.web.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.domain.Paiban;
import com.ruoyi.web.service.IPaibanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 医生排班Controller
 * 
 * @author 蛤蛤
 * @date 2022-12-27
 */
@RestController
@RequestMapping("/working/paiban")
public class PaibanController extends BaseController
{
    @Autowired
    private IPaibanService paibanService;

    /**
     * 查询医生排班列表
     */
//    @PreAuthorize("@ss.hasPermi('working:paiban:list')")
    @GetMapping("/list")
    public TableDataInfo list(Paiban paiban)
    {
        startPage();
        List<Paiban> list = paibanService.selectPaibanList(paiban);
        return getDataTable(list);
    }

    /**
     * 导出医生排班列表
     */
    @PreAuthorize("@ss.hasPermi('working:paiban:export')")
    @Log(title = "医生排班", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Paiban paiban)
    {
        List<Paiban> list = paibanService.selectPaibanList(paiban);
        ExcelUtil<Paiban> util = new ExcelUtil<Paiban>(Paiban.class);
        util.exportExcel(response, list, "医生排班数据");
    }

    /**
     * 获取医生排班详细信息
     */
    @PreAuthorize("@ss.hasPermi('working:paiban:query')")
    @GetMapping(value = "/{paiid}")
    public AjaxResult getInfo(@PathVariable("paiid") Long paiid)
    {
        return success(paibanService.selectPaibanByPaiid(paiid));
    }

    /**
     * 新增医生排班
     */
    @PreAuthorize("@ss.hasPermi('working:paiban:add')")
    @Log(title = "医生排班", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Paiban paiban)
    {
        return toAjax(paibanService.insertPaiban(paiban));
    }

    /**
     * 修改医生排班
     */
    @PreAuthorize("@ss.hasPermi('working:paiban:edit')")
    @Log(title = "医生排班", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Paiban paiban)
    {
        return toAjax(paibanService.updatePaiban(paiban));
    }

    /**
     * 删除医生排班
     */
    @PreAuthorize("@ss.hasPermi('working:paiban:remove')")
    @Log(title = "医生排班", businessType = BusinessType.DELETE)
	@DeleteMapping("/{paiids}")
    public AjaxResult remove(@PathVariable Long[] paiids)
    {
        return toAjax(paibanService.deletePaibanByPaiids(paiids));
    }
}
